package com.eshidai.simple_springboot.web;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.eshidai.simple_springboot.bean.User;
import com.eshidai.simple_springboot.service.HelloService;

@RestController
@RequestMapping(value="/user")
public class UserController {
	
	@Autowired
	public HelloService helloService;
	
	@RequestMapping(value="/",method=RequestMethod.GET)
	public List<User> getUserList() {
		User u1 = new User();
		u1.setId(123456L);
		u1.setName("eshidai");
		u1.setAge(28);
		
		List<User> list = new ArrayList<User>();
		list.add(u1);
		
		return list;
	}
	
	@RequestMapping(value="/",method=RequestMethod.POST)
	public String postUser(@ModelAttribute User user) {
		//。。。处理逻辑
		
		return "success";
	}
	
	@RequestMapping(value="/{id}",method=RequestMethod.GET)
	public User getUser(@PathVariable Long id) {
		//通过id来获取user
		//处理逻辑
		User u = helloService.getUser();
		
		
		return u;
	}
	
	@RequestMapping(value="/",method=RequestMethod.PUT)
	public String putUser(@ModelAttribute User user) {
		//。。。处理逻辑
		
		return "success";
	}
	
	@RequestMapping(value="/{id}",method=RequestMethod.DELETE)
	public String deleteUser(@PathVariable Long id) {
		//通过id来删除user
		//处理逻辑
		
		
		return "success";
	}
}
